/*
 * @Description: 
 * @Author: hanyu
 * @Date: 2022-03-02 16:27:19
 * @LastEditTime: 2022-03-18 10:23:46
 * @LastEditors: hanyu
 */
import Vue from 'vue'
import Router from 'vue-router'
import Home from '../views/home.vue'
// eslint-disable-next-line no-unused-vars
import cookie from '@/lib/cookie';
// import iView from 'view-design';



// 登录模块
const routers = [
  {
    path: '/',
    name: 'login',
    meta: {
      hideInMenu: true,
      title: '登录'
    },
    component: () => import('@/views/login/login.vue')
  },
  {
    path: '/home',
    name: 'home',
    meta: {
      title: '首页'
    },
    redirect: '/dataPage',
    component: Home,
    children:[
      {
        path: '/dataPage',
        name: 'DataPage',
        meta:{
          title: '数据面板'
        },
        component: () => import('@/views/dataPage/index.vue')
      },
      {
        path: '/web-data',
        name: 'WebData',
        meta:{
          title: '属地网站管理'
        },
        component: () => import('@/views/web-data/web-data.vue')
      },
      {
        path: '/account',
        name: 'Account',
        meta:{
          title: '属地社交账号管理'
        },
        component: () => import('@/views/account/index.vue')
      },
      {
        path: '/warning-info',
        name: 'WarningInfo',
        meta:{
          title: '今日预警信息'
        },
        component: () => import('@/views/warning-info/index.vue')
      },
      {
        path: '/special',
        name: 'Special',
        meta:{
          title: '专项行动'
        },
        component: () => import('@/views/special/index.vue')
      },
    ]
  }

  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]
Vue.use(Router)
const router = new Router({
  routes: routers
  // mode: 'routes'
});

router.beforeEach((to, from, next) => {
  console.log(to);
  // iView.LoadingBar.start();
  const token = cookie.getToken();
  if (!token && to.name != 'login') {
    // 未登录且要跳转的页面不是登录页
    next({
      name: 'login' // 跳转到登录页
    });
  }else{
    next();
  }
});


export default router
